﻿using System;
using System.Web;
namespace MikeKappel.Com.CS
{
    public partial class Helper
    {
        public enum ApplicationPathType
        {
            /// <summary>
            /// Internal or Local URLs do not include Domain name
            /// and never end in "\"
            /// </summary>
            Internal,
            /// <summary>
            /// External or Absolute URLs include Domain and http or https
            /// in addtion to the Internal or local Application Path
            /// </summary>
            External
        }
        /// <summary>
        /// HttpContext.Current.Request.ApplicationPath
        /// Never ends with "/"
        /// </summary>
        /// <returns>Application Path</returns>
        public static String ApplicationPath()
        {
            return ApplicationPath(ApplicationPathType.Internal);
        }
        /// <summary>
        /// HttpContext.Current.Request.ApplicationPath
        /// Never ends with "/"
        /// </summary>
        /// <returns>Application Path</returns>
        public static String ApplicationPath(ApplicationPathType urlType)
        {
            if (urlType == ApplicationPathType.Internal)
            {
                return (HttpContext.Current.Request.ApplicationPath == "/") ? "" : HttpContext.Current.Request.ApplicationPath;
            }
            else
            {
                return ((HttpContext.Current.Request.IsSecureConnection) ? "https://" : "http://") + HttpContext.Current.Request.Url.Host + (HttpContext.Current.Request.Url.Port.ToString().IndexOf("80") == 0 ? "" : ":" + (HttpContext.Current.Request.Url.Port.ToString())) + ApplicationPath(ApplicationPathType.Internal);
            }
        }
    }
}